//package com.bruce.practice.es.service;
//
//import com.bruce.practice.es.bean.News;
//import com.bruce.utils.json.GsonUtils;
//import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
//import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
//import org.elasticsearch.action.index.IndexRequest;
//import org.elasticsearch.client.RequestOptions;
//import org.elasticsearch.client.RestHighLevelClient;
//import org.elasticsearch.cluster.metadata.MappingMetaData;
//import org.elasticsearch.common.collect.ImmutableOpenMap;
//import org.elasticsearch.common.xcontent.XContentType;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.io.IOException;
//
///**
// * @author luotuan
// * @Description
// * @create 2020-06-23 13:32
// **/
////@Service
//public class InsertService {
//    //@Autowired
//    RestHighLevelClient restHighLevelClient;
//
//    public void addTest() {
//        IndexRequest indexRequest = new IndexRequest("demo","_doc");
//        News news = new News();
//        news.setTitle("中国产小型无人机的“对手”来了，俄微型拦截导弹便宜量又多");
//        news.setTag("军事");
//        news.setPublishTime("2018-01-24T23:59:30Z");
//        String source = GsonUtils.toJson(news);
//        indexRequest.source(source, XContentType.JSON);
//        try {
//            restHighLevelClient.index(indexRequest);
//        } catch (IOException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }
//    }
//
//    public void searchMapping(){
//        ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings;
//        try {
//            GetMappingsRequest request = new GetMappingsRequest();
//            request.indices("gy_oss_db");
//            //request.types("_doc");
//            GetMappingsResponse getMappingResponse = restHighLevelClient.indices().getMapping(request, RequestOptions.DEFAULT);
//            getMappingResponse.mappings().get("gy_oss_db");
//            getMappingResponse.getMappings().forEach(e -> {
//                String key = e.key;
//                ImmutableOpenMap<String, MappingMetaData> value = e.value;
//                value.forEach(v -> {
//                    System.out.println(key + "|" + v.key + "|" + v.value.getSourceAsMap());
//                });
//            });
//        }catch (Exception e){
//            e.printStackTrace();
//        }
//    }
//}
